{
  axios.defaults.baseURL = 'http://cba.itlike.com/public/index.php?s=/api'
  const app = new Vue({
    el: '#app',
    created() {
      this.getDataList()
    },
    data: {
      goodsList: [],
      flag: 0,
      iFlag: localStorage.getItem('iFlag') === 'false' ? false : true,
      flagI: false,
      navList: [`综合`, `销量`]
    },
    methods: {
      // 最早的渲染
      async getDataList() {
        const { data: res } = await axios.get('/goods/list', {
          params: {
            categoryId: localStorage.getItem('category_id'),
            sortType: 'all'
          }
        })
        this.goodsList = res.data.list.data
      },
      // 销量渲染
      async getNumberDatalist() {
        const { data: res } = await axios.get('/goods/list', {
          params: {
            categoryId: localStorage.getItem('category_id'),
            sortType: 'sales'
          }
        })
        this.goodsList = res.data.list.data
      },
      // 价格渲染从低到高
      async getLowPriceDatalist() {
        const { data: res } = await axios.get('/goods/list', {
          params: {
            categoryId: localStorage.getItem('category_id'),
            sortType: 'price',
            sortPrice: '0'
          }
        })
        this.goodsList = res.data.list.data
      },
      // 价格渲染从高到低
      async getHighPriceDatalist() {
        const { data: res } = await axios.get('/goods/list', {
          params: {
            categoryId: localStorage.getItem('category_id'),
            sortType: 'price',
            sortPrice: '1'
          }
        })
        this.goodsList = res.data.list.data
      },
      // 导航栏点击事件
      navClick(index) {
        this.flag = index
        this.flagI = false
        if (index === 0) this.getDataList()
        if (index === 1) {
          this.getNumberDatalist()
        }
      },
      // 价格点击事件
      priceClick() {
        this.flag = 2
        this.flagI = !this.flagI
        if (this.flagI) {
          this.getLowPriceDatalist()
        } else {
          this.getHighPriceDatalist()
        }
      },
      // 商品组点击跳转事件
      gogogo(id) {
        localStorage.setItem('goodsId', id)
        localStorage.setItem('where', 'goodslist')
        location.href = '../goods/index.html'
      },
      // 字体图标点击事件
      iClick() {
        this.iFlag = !this.iFlag
        localStorage.setItem('iFlag', this.iFlag)
      }
    }
  })
}
